package com.melesta.expansions;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Handler;
import com.melesta.engine.Log;
import com.melesta.engine.R.array;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ExpansionsManager
{
  static ExpansionsManager instance;
  private List<IEngineExpansion> expansions = new LinkedList();

  protected ExpansionsManager(Context paramContext)
  {
    String[] arrayOfString = paramContext.getResources().getStringArray(R.array.expansions);
    int i = arrayOfString.length;
    int j = 0;
    while (true)
      if (j < i)
      {
        String str = arrayOfString[j];
        Log.d("java", "load expansion " + str);
        try
        {
          Object localObject2 = Class.forName(str).newInstance();
          localObject1 = localObject2;
          if ((localObject1 instanceof IEngineExpansion))
            addExpansion((IEngineExpansion)localObject1);
          j++;
        }
        catch (IllegalAccessException localIllegalAccessException)
        {
          while (true)
          {
            Log.e("java", "IllegalAccessException: " + localIllegalAccessException.getMessage());
            localObject1 = null;
          }
        }
        catch (InstantiationException localInstantiationException)
        {
          while (true)
          {
            Log.e("java", "InstantiationException: " + localInstantiationException.getMessage());
            localObject1 = null;
          }
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
          while (true)
          {
            Log.e("java", "ClassNotFoundException: " + localClassNotFoundException.getMessage());
            Object localObject1 = null;
          }
        }
      }
  }

  public static ExpansionsManager getInstance(Context paramContext)
  {
    if (instance == null)
      instance = new ExpansionsManager(paramContext);
    return instance;
  }

  public boolean addExpansion(IEngineExpansion paramIEngineExpansion)
  {
    synchronized (this.expansions)
    {
      if (this.expansions.add(paramIEngineExpansion))
      {
        paramIEngineExpansion.onAddExpansion();
        return true;
      }
      return false;
    }
  }

  public void clear()
  {
    synchronized (this.expansions)
    {
      this.expansions.clear();
      return;
    }
  }

  public void fireActivityResult(Context paramContext, int paramInt1, int paramInt2, Intent paramIntent)
  {
    Iterator localIterator = this.expansions.iterator();
    while (localIterator.hasNext())
      ((IEngineExpansion)localIterator.next()).onActivityResult(paramContext, paramInt1, paramInt2, paramIntent);
  }

  public void fireActivityStateChange(ActivityState paramActivityState, Context paramContext, Handler paramHandler)
  {
    Iterator localIterator = this.expansions.iterator();
    while (localIterator.hasNext())
      ((IEngineExpansion)localIterator.next()).onActivitySateChange(paramActivityState, paramContext, paramHandler);
  }

  public void free()
  {
    clear();
    instance = null;
  }

  public IEngineExpansion getExpansion(Class paramClass)
  {
    Iterator localIterator = this.expansions.iterator();
    while (localIterator.hasNext())
    {
      IEngineExpansion localIEngineExpansion = (IEngineExpansion)localIterator.next();
      if (paramClass.isInstance(localIEngineExpansion))
        return localIEngineExpansion;
    }
    return null;
  }

  public boolean removeExpansion(IEngineExpansion paramIEngineExpansion)
  {
    synchronized (this.expansions)
    {
      if (this.expansions.remove(paramIEngineExpansion))
      {
        paramIEngineExpansion.onRemoveExpansion();
        return true;
      }
      return false;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.melesta.expansions.ExpansionsManager
 * JD-Core Version:    0.6.2
 */